#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author: wangxiaoming 2021-11-16
# desc: thermal测试类

import enum
import unittest
import os
import time
import struct
from ctypes import *
from mainunit_common import *
from mainunit_api import *

class testself_lsensor_drv(unittest.TestCase):    
    def testself1_lsensor_drv_off(self):
        print(f'\t==================================')
        expected=ECODE_OK
        valueset=c_int(0)
        
        ret = lsensor_drv_init()
        print(f'\tstep. call api: lsensor_drv_init, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        ret = lsensor_drv_set_status(valueset)        
        print(f'\tstep. call api: lsensor_drv_set_status, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        status = c_int(-1)
        ret = lsensor_drv_get_status(pointer(status))        
        print(f'\tstep. call api: lsensor_drv_get_status, actual value={ret}, expected value={expected}')		
        self.assertEqual(ret, expected)
		
        print(f'\tstep. compare value, actual value={status}, expected value={valueset}')		
        self.assertEqual(status.value, valueset.value)
        
        ret = lsensor_drv_uinit()
        print(f'\tstep. call api: lsensor_drv_uinit, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
		
        print('\t**********************************')

    def testself2_lsensor_drv_on(self):
        print(f'\t==================================')
        expected=ECODE_OK
        valueset=c_int(1)
        
        ret = lsensor_drv_init()
        print(f'\tstep. call api: lsensor_drv_init, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        ret = lsensor_drv_set_status(valueset)        
        print(f'\tstep. call api: lsensor_drv_set_status, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        status = c_int(-1)
        ret = lsensor_drv_get_status(pointer(status))        
        print(f'\tstep. call api: lsensor_drv_get_status, actual value={ret}, expected value={expected}')		
        self.assertEqual(ret, expected)
		
        print(f'\tstep. compare value, actual value={status}, expected value={valueset}')		
        self.assertEqual(status.value, valueset.value)
        
        ret = lsensor_drv_uinit()
        print(f'\tstep. call api: lsensor_drv_uinit, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)

        print('\t**********************************')

    def testself3_lsensor_drv_getdata(self):
        print(f'\t==================================')
        expected=ECODE_OK
        valueset=c_int(1)
        
        ret = lsensor_drv_init()
        print(f'\tstep. call api: lsensor_drv_init, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)
        
        ret = lsensor_drv_set_status(valueset)        
        print(f'\tstep. call api: lsensor_drv_set_status, actual value={ret}, expected value={expected}')        
        self.assertEqual(ret, expected)
        
        status = c_float(-1)
        ret = lsensor_drv_get_als(pointer(status))        
        print(f'\tstep. call api: lsensor_drv_get_als, actual value={ret}, expected value={expected} RETURN VALUE=[{status.value}]')
        
        txt = sp_input("PLEASE COVER DEVICE WITH HAND AND INPUT ANY KEY TO CONTINUE\n")        
        
        status = c_float(-1)
        ret = lsensor_drv_get_als(pointer(status))
        print(f'\tstep. call api: lsensor_drv_get_als, actual value={ret}, expected value={expected} RETURN VALUE=[{status.value}]')
        
        txt = sp_input("PLEASE CHECK WHETHER THE TWO VALUES ARE DIFFERENT , DIFFERENT, PLEASE ENTER 1\n")
        self.assertEqual(txt, '1')
        
        ret = lsensor_drv_uinit()
        print(f'\tstep. call api: lsensor_drv_uinit, actual value={ret}, expected value={expected}')
        self.assertEqual(ret, expected)

        print('\t**********************************')